//
//  HomeViewController.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/2/25.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation

class HomeViewController: BaseTRTCViewController {
    
    var conts:[IconData] = [
        IconData.init(title: "主持会议", image: "toolbar_stop_video_normal"),
        IconData.init(title: "加入会议", image: "toolbar_mute_tele_normal"),
        IconData.init(title: "邀请分享", image: "toolbar_mute_voip_normal"),
    ]
    
    override func loadView() {
        let view = NSView.init(frame: NSMakeRect(0, 0, kHomeWinWidth, kHomeWinHeight))
        view.wantsLayer = true
        view.layer?.backgroundColor = NSColor.white.cgColor
        self.view = view
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.setupUI()
    }
    
    func setupUI() {
        self.view.addSubview(bgImageV)
        bgImageV.snp.makeConstraints { (make) in
            make.size.equalTo(bgImageV.image!.size)
            make.top.centerX.equalToSuperview()
        }
        
        self.view.addSubview(contLab)
        contLab.snp.makeConstraints { (make) in
            make.height.equalTo(20)
            make.top.equalTo(30)
            make.left.equalTo(20)
        }
        
        self.view.addSubview(contentView)
        contentView.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-60)
            make.height.equalTo(80)
            make.top.equalTo(70)
            make.centerX.equalToSuperview()
        }
        self.initContents(inView: contentView)
       
        
        self.view.addSubview(setBtn)
        setBtn.snp.makeConstraints { (make) in
            make.size.equalTo(setBtn.image!.size)
            make.right.equalToSuperview().offset(-20)
            make.top.equalTo(30)
        }
    }
    
    
    lazy var contLab: NSLabel = {
        let lab = NSLabel.label(title: "同一个世界 同一个会议", textColor: color_gray(255), font: NSFont.systemFont(ofSize: 18))
        lab.sizeToFit()
        return lab
    }()
    
    lazy var bgImageV: NSImageView = {
        let imageV = NSImageView.init(image: NSImage.init(named: NSImage.Name.init("icon_home_banner"))!)
        return imageV
    }()
    
    lazy var contentView: NSView = {
        let view = NSView()
        return view
    }()
    
    func initContents(inView:NSView) {
        inView.layoutSubtreeIfNeeded()
        let kW = CGFloat(60)
        let kH = CGFloat(80)
        let space = (inView.frame.width-kW*CGFloat(self.conts.count))/CGFloat(self.conts.count-1)
        for (inx,val) in self.conts.enumerated() {
            let view = Icon.init(data: val)
            inView.addSubview(view)
            view.snp.makeConstraints { (make) in
                make.width.equalTo(kW)
                make.height.equalTo(kH)
                make.left.equalTo((space+kW)*CGFloat(inx))
                make.centerY.equalToSuperview()
            }
        }
    }
    
    lazy var setBtn: ZHButton = {
        let btn = ZHButton()
        btn.normalImage = NSImage.image(name:"icon_settingss")!
        btn.selectedImage = NSImage.image(name:"icon_settingss")!
        return btn
    }()
}
